package com.qf.java2107.yb.hotel.controller.foodtype_bak;

import com.qf.java2107.yb.hotel.common.ResultVO;
import com.qf.java2107.yb.hotel.entity.BeanFactory;
import com.qf.java2107.yb.hotel.service.FoodTypeService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ghy
 * @version 1.0
 * @date 2021-10-25
 **/
//@WebServlet("/foodtype/del")
public class FoodTypeDelController extends HttpServlet {

    private FoodTypeService foodTypeService = (FoodTypeService) BeanFactory.getBean("foodTypeService");

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String typeId = request.getParameter("typeId");

        ResultVO vo = foodTypeService.deleteById(Integer.parseInt(typeId));

        if(vo.getSuccess()) {
            response.sendRedirect(request.getContextPath() + "/foodtype/search");
        } else {
            response.getWriter().write((String) vo.getData());
        }

    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

}
